<!-- 地图 -->
<template>
    <div class="map" :style="boxStyle">
        <div class="inner-content">
            <template v-if="element.eles.customFeature.type === 'withmap'">
                <div class="map-component">
                    <el-amap :center="mapCenter" :zoom="12">
                        <el-amap-marker :position="mapCenter"></el-amap-marker>
                    </el-amap>
                </div>
            </template>
            <div class="map-link">
                <div class="map-link-icon">
                    <el-icon><icon-map-address /></el-icon>
                </div>
                <div
                    :style="{
                        color: element.eles.style.color,
                        textAlign: element.eles.style['text-align'],
                        fontSize: element.eles.style['font-size'],
                        fontStyle: element.eles.style['font-style'],
                        fontWeight: element.eles.style['font-weight'],
                        textDecoration: element.eles.style['text-decoration']
                    }"
                    class="map-link-title"
                >
                    {{ element.eles.content }}
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { defineComponent, toRefs, computed } from 'vue'
export default defineComponent({
    name: 'WidgetMap',
    props: {
        element: {
            type: Object,
            default: () => ({})
        }
    },
    setup(props, { emit }) {
        const { element } = toRefs(props)

        const boxStyle = computed(() => {
            const style = element.value.eles.style || {}
            return {
                width: style.width,
                height: style.height,
                marginTop: style['margin-top'],
                marginLeft: style['margin-left'],
                backgroundColor: style['background-color']
            }
        })

        const mapCenter = computed(() => {
            const { lng, lat } = element.value.eles.customFeature || {}
            return [lng, lat]
        })
        
        return {
            element,
            boxStyle,
            mapCenter
        }
    }
})
</script>

<style lang="less" scoped>
@import './widget-map.less';
</style>